<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        span {
            display: inline-block;
            width: 50px;
            height: 50px;
            line-height: 50px;
            font-size: 20px;
            text-align: center;
            background: #ccc;
            color: #000;
            margin-right: 10px;
            margin-top: 10px;

        }
    </style>
</head>

<body>
    <h1>定义一个含有30个整型元素的数组，按顺序分别赋予从2开始的偶数；然后按顺序每五个数求出一个平均值，放在另一个数组中并输出。试编程。</h1>
    <input type="button" id="btn" value="结果">
    <div id="box">

        <!-- <span></span> -->

    </div>
</body>
<script>
    var btn = document.getElementById("btn");
    var box = document.getElementById("box");
    //计算函数
    function count() {
        var arr = new Array();
        var brr = new Array();
        var m = 0;
        var n = 0;
        var html = '';
        var j = 0;
        for (var i = 0; i < 30; i++) {
            m++;
            arr[i] = 2 * (i + 1);
            n += arr[i];
            if (m % 5 == 0) {
                brr[j] = n / 5;
                html += '<span>' + brr[j] + '</span>';
                j++;

            }

        }
        box.innerHTML = html;
    }
    btn.onclick = function () {
        count();
    }
</script>

</html>